﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using HtmlAgilityPack;

namespace Flights
{
    class AirMekongRegister : FlightRegister
    {
        protected string _market1 = "";
        protected string _market2 = "";

        public override void Register(FlightRegisterParameters param)
        {
            if (param.BookingType == "oneway")
            {
                OneWayRegister(param);
            }
            else if (param.BookingType == "roundtrip")
            {
                RoundTripResgister(param);
            }
        }

        private void OneWayRegister(FlightRegisterParameters param)
        {
            _result = null;

            string fileName = Path.GetTempFileName();

            string cookie =
                "ASP.NET_SessionId=maebhn55333a1unuwov03z45; CONTROLGROUPCONTACT_ContactInputView_dsadsadsada=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|BMV&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=dasdasd&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=dsada&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=7631296&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=abnc%40gmail.com; CONTROLGROUPCONTACT_ContactInputView_fdsfsdfdf=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|DLI&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=fsfdsf&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=34242&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=1761619&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=thienan289%40gmail.com; __utma=187758136.1032547902.1356189845.1356195522.1356225069.3; __utmb=187758136.1.10.1356225069; __utmc=187758136; __utmz=187758136.1356225069.3.3.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)";
            WebScraping webScraping = new AirMekongWebSraping();
            IWebScrapingDelegate webScrapingDelegate = webScraping.GetWebScrapingDelegate(param.BookingType);
            webScrapingDelegate.DownloadWebPage(param, fileName, cookie);

            GetPostData(fileName, param);
            string postData = string.Format("__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUBMGRk77h9CNekodLMZhdJu3riPx9ebN8%3D&pageToken=&AvailabilitySearchInputScheduleSelectView%24RadioButtonMarketStructure=OneWay&originStation1=HAN&AvailabilitySearchInputScheduleSelectView%24TextBoxMarketOrigin1=HAN&destinationStation1=SGN&AvailabilitySearchInputScheduleSelectView%24TextBoxMarketDestination1=SGN&AvailabilitySearchInputScheduleSelectView%24DropDownListMarketDay1=25&AvailabilitySearchInputScheduleSelectView%24DropDownListMarketMonth1=2012-12&AvailabilitySearchInputScheduleSelectView%24DropDownListMarketDateRange1=0%7C4&date_picker=2012-12-25&originStation2=&AvailabilitySearchInputScheduleSelectView%24TextBoxMarketOrigin2=%C4%90i%E1%BB%83m+%C4%91i...&destinationStation2=&AvailabilitySearchInputScheduleSelectView%24TextBoxMarketDestination2=%C4%90i%E1%BB%83m+%C4%91%E1%BA%BFn...&AvailabilitySearchInputScheduleSelectView%24DropDownListMarketDay2=30&AvailabilitySearchInputScheduleSelectView%24DropDownListMarketMonth2=2012-12&AvailabilitySearchInputScheduleSelectView%24DropDownListMarketDateRange2=0%7C4&date_picker=2012-12-30&AvailabilitySearchInputScheduleSelectView%24DropDownListPassengerType_ADT=1&AvailabilitySearchInputScheduleSelectView%24DropDownListPassengerType_CHD=0&AvailabilitySearchInputScheduleSelectView%24DropDownListPassengerType_INFANT=0&AvailabilitySearchInputScheduleSelectView%24DropDownListSearchBy=columnView&ControlGroupScheduleSelectView%24AvailabilityInputScheduleSelectView%24HiddenFieldTabIndex1=3&ControlGroupScheduleSelectView%24AvailabilityInputScheduleSelectView%24market1={0}&ControlGroupScheduleSelectView%24AgreementInputScheduleSelectView%24CheckBoxAgreement=on&ControlGroupScheduleSelectView%24ButtonSubmit=Ti%E1%BA%BFp+t%E1%BB%A5c", _market1);
            WebClientEx webClient = WebClientEx.CreateMekongAirWebClient("https://booking.airmekong.com.vn/ScheduleSelect.aspx");
            webClient.Headers["Cookie"] =
                "ASP.NET_SessionId=maebhn55333a1unuwov03z45; CONTROLGROUPCONTACT_ContactInputView_dsadsadsada=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|BMV&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=dasdasd&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=dsada&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=7631296&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=abnc%40gmail.com; CONTROLGROUPCONTACT_ContactInputView_fdsfsdfdf=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|DLI&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=fsfdsf&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=34242&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=1761619&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=thienan289%40gmail.com; __utma=187758136.1032547902.1356189845.1356195522.1356225069.3; __utmb=187758136.1.10.1356225069; __utmc=187758136; __utmz=187758136.1356225069.3.3.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)";
            webClient.DownloadFileEx(postData, fileName);

            postData = string.Format(
                "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUBMGRk77h9CNekodLMZhdJu3riPx9ebN8%3D&pageToken=&AvailabilitySearchInputContactView%24RadioButtonMarketStructure=OneWay&originStation1=HAN&AvailabilitySearchInputContactView%24TextBoxMarketOrigin1=HAN&destinationStation1=SGN&AvailabilitySearchInputContactView%24TextBoxMarketDestination1=SGN&AvailabilitySearchInputContactView%24DropDownListMarketDay1=25&AvailabilitySearchInputContactView%24DropDownListMarketMonth1=2012-12&AvailabilitySearchInputContactView%24DropDownListMarketDateRange1=0%7C4&date_picker=2012-12-25&originStation2=&AvailabilitySearchInputContactView%24TextBoxMarketOrigin2=%C4%90i%E1%BB%83m+%C4%91i...&destinationStation2=&AvailabilitySearchInputContactView%24TextBoxMarketDestination2=%C4%90i%E1%BB%83m+%C4%91%E1%BA%BFn...&AvailabilitySearchInputContactView%24DropDownListMarketDay2=30&AvailabilitySearchInputContactView%24DropDownListMarketMonth2=2012-12&AvailabilitySearchInputContactView%24DropDownListMarketDateRange2=0%7C4&date_picker=2012-12-30&AvailabilitySearchInputContactView%24DropDownListPassengerType_ADT=1&AvailabilitySearchInputContactView%24DropDownListPassengerType_CHD=0&AvailabilitySearchInputContactView%24DropDownListPassengerType_INFANT=0&AvailabilitySearchInputContactView%24DropDownListSearchBy=columnView&CONTROLGROUPCONTACT%24ContactInputView%24DropDownListTitle=MR&CONTROLGROUPCONTACT%24ContactInputView%24TextBoxLastName={1}&CONTROLGROUPCONTACT%24ContactInputView%24TextBoxFirstName={0}&CONTROLGROUPCONTACT%24ContactInputView%24TextBoxAddressLine1=ttt&CONTROLGROUPCONTACT%24ContactInputView%24DropDownListStateProvince=VN%7CSGN&CONTROLGROUPCONTACT%24ContactInputView%24DropDownListCountry=VN&CONTROLGROUPCONTACT%24ContactInputView%24TextBoxHomePhone={2}&CONTROLGROUPCONTACT%24ContactInputView%24TextBoxEmailAddress={3}&CONTROLGROUPCONTACT%24ContactInputView%24TextBoxFax=7633849&CONTROLGROUPCONTACT%24ItineraryDistributionInputView%24Distribution=0&CONTROLGROUPCONTACT%24ButtonSubmit=Ti%E1%BA%BFp+t%E1%BB%A5c",
                param.FirstName, param.LastName, param.Phone, param.Email);

            webClient = WebClientEx.CreateMekongAirWebClient("https://booking.airmekong.com.vn/Contact.aspx");
            webClient.Headers["Cookie"] =
                "ASP.NET_SessionId=maebhn55333a1unuwov03z45; CONTROLGROUPCONTACT_ContactInputView_dsadsadsada=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|BMV&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=dasdasd&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=dsada&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=7631296&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=abnc%40gmail.com; CONTROLGROUPCONTACT_ContactInputView_fdsfsdfdf=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|DLI&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=fsfdsf&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=34242&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=1761619&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=thienan289%40gmail.com; __utma=187758136.1032547902.1356189845.1356195522.1356225069.3; __utmb=187758136.1.10.1356225069; __utmc=187758136; __utmz=187758136.1356225069.3.3.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)";
            webClient.DownloadFileEx(postData, fileName);

            postData = string.Format(
                "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUBMGRk77h9CNekodLMZhdJu3riPx9ebN8%3D&pageToken=&AvailabilitySearchInputPassengerView%24RadioButtonMarketStructure=OneWay&originStation1=HAN&AvailabilitySearchInputPassengerView%24TextBoxMarketOrigin1=HAN&destinationStation1=SGN&AvailabilitySearchInputPassengerView%24TextBoxMarketDestination1=SGN&AvailabilitySearchInputPassengerView%24DropDownListMarketDay1=25&AvailabilitySearchInputPassengerView%24DropDownListMarketMonth1=2012-12&AvailabilitySearchInputPassengerView%24DropDownListMarketDateRange1=0%7C4&date_picker=2012-12-25&originStation2=&AvailabilitySearchInputPassengerView%24TextBoxMarketOrigin2=%C4%90i%E1%BB%83m+%C4%91i...&destinationStation2=&AvailabilitySearchInputPassengerView%24TextBoxMarketDestination2=%C4%90i%E1%BB%83m+%C4%91%E1%BA%BFn...&AvailabilitySearchInputPassengerView%24DropDownListMarketDay2=30&AvailabilitySearchInputPassengerView%24DropDownListMarketMonth2=2012-12&AvailabilitySearchInputPassengerView%24DropDownListMarketDateRange2=0%7C4&date_picker=2012-12-30&AvailabilitySearchInputPassengerView%24DropDownListPassengerType_ADT=1&AvailabilitySearchInputPassengerView%24DropDownListPassengerType_CHD=0&AvailabilitySearchInputPassengerView%24DropDownListPassengerType_INFANT=0&AvailabilitySearchInputPassengerView%24DropDownListSearchBy=columnView&CONTROLGROUPPASSENGER%24PassengerInputViewPassengerView%24DropDownListTitle_0=MR&CONTROLGROUPPASSENGER%24PassengerInputViewPassengerView%24TextBoxLastName_0=ngoc&CONTROLGROUPPASSENGER%24PassengerInputViewPassengerView%24TextBoxFirstName_0=nguyen&CONTROLGROUPPASSENGER%24PassengerInputViewPassengerView%24TextBoxProgramNumber_0=&CONTROLGROUPPASSENGER%24PassengerInputViewPassengerView%24DropDownListProgram_0=UAT&CONTROLGROUPPASSENGER%24ButtonSubmit=Ti%E1%BA%BFp+t%E1%BB%A5c");
            webClient = WebClientEx.CreateMekongAirWebClient("https://booking.airmekong.com.vn/Passenger.aspx");
            webClient.Headers["Cookie"] =
                "ASP.NET_SessionId=maebhn55333a1unuwov03z45; CONTROLGROUPCONTACT_ContactInputView_dsadsadsada=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|BMV&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=dasdasd&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=dsada&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=7631296&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=abnc%40gmail.com; CONTROLGROUPCONTACT_ContactInputView_fdsfsdfdf=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|DLI&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=fsfdsf&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=34242&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=1761619&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=thienan289%40gmail.com; __utma=187758136.1032547902.1356189845.1356195522.1356225069.3; __utmb=187758136.1.10.1356225069; __utmc=187758136; __utmz=187758136.1356225069.3.3.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)";
            webClient.DownloadFileEx(postData, fileName);

            postData = string.Format(
                "__EVENTTARGET=CONTROLGROUPPAYMENTBOTTOM%24PaymentInputViewPaymentView&__EVENTARGUMENT=HOLD&__VIEWSTATE=%2FwEPDwUBMGRk77h9CNekodLMZhdJu3riPx9ebN8%3D&pageToken=&AvailabilitySearchInputPaymentView%24RadioButtonMarketStructure=OneWay&originStation1=HAN&AvailabilitySearchInputPaymentView%24TextBoxMarketOrigin1=HAN&destinationStation1=SGN&AvailabilitySearchInputPaymentView%24TextBoxMarketDestination1=SGN&AvailabilitySearchInputPaymentView%24DropDownListMarketDay1=25&AvailabilitySearchInputPaymentView%24DropDownListMarketMonth1=2012-12&AvailabilitySearchInputPaymentView%24DropDownListMarketDateRange1=0%7C4&date_picker=2012-12-25&originStation2=&AvailabilitySearchInputPaymentView%24TextBoxMarketOrigin2=%C4%90i%E1%BB%83m+%C4%91i...&destinationStation2=&AvailabilitySearchInputPaymentView%24TextBoxMarketDestination2=%C4%90i%E1%BB%83m+%C4%91%E1%BA%BFn...&AvailabilitySearchInputPaymentView%24DropDownListMarketDay2=30&AvailabilitySearchInputPaymentView%24DropDownListMarketMonth2=2012-12&AvailabilitySearchInputPaymentView%24DropDownListMarketDateRange2=0%7C4&date_picker=2012-12-30&AvailabilitySearchInputPaymentView%24DropDownListPassengerType_ADT=1&AvailabilitySearchInputPaymentView%24DropDownListPassengerType_CHD=0&AvailabilitySearchInputPaymentView%24DropDownListPassengerType_INFANT=0&AvailabilitySearchInputPaymentView%24DropDownListSearchBy=columnView&CONTROLGROUPPAYMENTBOTTOM%24PaymentInputViewPaymentView%24DropDownListPaymentMethodCode=ExternalAccount%3AAX&CONTROLGROUPPAYMENTBOTTOM%24PaymentInputViewPaymentView%24TextBoxAMT=1.576.500&CONTROLGROUPPAYMENTBOTTOM%24PaymentInputViewPaymentView%24TextBoxACCTNO=&CONTROLGROUPPAYMENTBOTTOM%24PaymentInputViewPaymentView%24DropDownListEXPDAT_Month=12&CONTROLGROUPPAYMENTBOTTOM%24PaymentInputViewPaymentView%24DropDownListEXPDAT_Year=2012&CONTROLGROUPPAYMENTBOTTOM%24PaymentInputViewPaymentView%24TextBoxCC__AccountHolderName=&CONTROLGROUPPAYMENTBOTTOM%24PaymentInputViewPaymentView%24TextBoxCC__VerificationCode=");
            webClient = WebClientEx.CreateMekongAirWebClient("https://booking.airmekong.com.vn/Payment.aspx");
            webClient.Headers["Cookie"] =
                "ASP.NET_SessionId=maebhn55333a1unuwov03z45; CONTROLGROUPCONTACT_ContactInputView_dsadsadsada=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|BMV&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=dasdasd&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=dsada&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=7631296&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=abnc%40gmail.com; CONTROLGROUPCONTACT_ContactInputView_fdsfsdfdf=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|DLI&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=fsfdsf&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=34242&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=1761619&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=thienan289%40gmail.com; __utma=187758136.1032547902.1356189845.1356195522.1356225069.3; __utmb=187758136.1.10.1356225069; __utmc=187758136; __utmz=187758136.1356225069.3.3.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)";
            webClient.DownloadFileEx(postData, fileName);

            postData = string.Format(
                       "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUBMGRk77h9CNekodLMZhdJu3riPx9ebN8%3D&pageToken=&AvailabilitySearchInputPaymentView%24RadioButtonMarketStructure=RoundTrip&originStation1=HAN&AvailabilitySearchInputPaymentView%24TextBoxMarketOrigin1=HAN&destinationStation1=SGN&AvailabilitySearchInputPaymentView%24TextBoxMarketDestination1=SGN&AvailabilitySearchInputPaymentView%24DropDownListMarketDay1=25&AvailabilitySearchInputPaymentView%24DropDownListMarketMonth1=2012-12&AvailabilitySearchInputPaymentView%24DropDownListMarketDateRange1=0%7C4&date_picker=2012-12-25&originStation2=SGN&AvailabilitySearchInputPaymentView%24TextBoxMarketOrigin2=SGN&destinationStation2=HAN&AvailabilitySearchInputPaymentView%24TextBoxMarketDestination2=HAN&AvailabilitySearchInputPaymentView%24DropDownListMarketDay2=30&AvailabilitySearchInputPaymentView%24DropDownListMarketMonth2=2012-12&AvailabilitySearchInputPaymentView%24DropDownListMarketDateRange2=0%7C4&date_picker=2012-12-30&AvailabilitySearchInputPaymentView%24DropDownListPassengerType_ADT=1&AvailabilitySearchInputPaymentView%24DropDownListPassengerType_CHD=0&AvailabilitySearchInputPaymentView%24DropDownListPassengerType_INFANT=0&AvailabilitySearchInputPaymentView%24DropDownListSearchBy=columnView&DropdowDS=ABO&CONTROLGROUPPAYMENTBOTTOM%24ButtonSubmit=Thanh+to%C3%A1n");
            webClient = WebClientEx.CreateMekongAirWebClient("https://booking.airmekong.com.vn/Payment.aspx");
            webClient.Headers["Cookie"] =
                "ASP.NET_SessionId=maebhn55333a1unuwov03z45; CONTROLGROUPCONTACT_ContactInputView_dsadsadsada=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|BMV&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=dasdasd&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=dsada&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=7631296&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=abnc%40gmail.com; CONTROLGROUPCONTACT_ContactInputView_fdsfsdfdf=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|DLI&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=fsfdsf&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=34242&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=1761619&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=thienan289%40gmail.com; __utma=187758136.1032547902.1356189845.1356195522.1356225069.3; __utmb=187758136.1.10.1356225069; __utmc=187758136; __utmz=187758136.1356225069.3.3.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)";
            webClient.DownloadFileEx(postData, fileName);
            ParseResult(fileName);
            File.Delete(fileName);

        }

        private void ParseResult(string fileName)
        {
            HtmlDocument document = new HtmlDocument();
            document.Load(fileName);

            _result = null;
            HtmlNode root = document.DocumentNode;
            HtmlNode bookIdNode = root.SelectSingleNode("//span[@id='matdatcho']");
            if (null == bookIdNode)
            {
                return;
            }

            string bookId = Utilities.ExtractNumberAndCharacter(bookIdNode.InnerText);
            HtmlNode priceDisplayTableNode = root.SelectSingleNode("//table[@id='priceDisplayTable']");
            if (null == priceDisplayTableNode)
            {
                return;
            }

            HtmlNode feeBeforeTaxNode = priceDisplayTableNode.SelectSingleNode(".//tr[@class='farePriceFee']/td[@class='right']");
            if (null == feeBeforeTaxNode)
            {
                return;
            }

            string feeBeforeTax = Utilities.ExtractNumber(feeBeforeTaxNode.InnerText);

            HtmlNode taxNode = priceDisplayTableNode.SelectSingleNode(".//tr[@class='feeTaxesFee']/td[@class='right']");
            if (null == taxNode)
            {
                return;
            }

            string tax = Utilities.ExtractNumber(taxNode.InnerText);

            HtmlNode totalFeeNode = priceDisplayTableNode.SelectSingleNode(".//tr[@class='totalPrice']/td[@class='right']");
            if (null == totalFeeNode)
            {
                return;
            }

            string totalFee = Utilities.ExtractNumber(totalFeeNode.InnerText);

            _result = new RegisterResult();
            _result.BookId = bookId;
            _result.FeeBeforeTax = feeBeforeTax;
            _result.Tax = tax;
            _result.TotalFee = totalFee;
        }

        private void RoundTripResgister(FlightRegisterParameters param)
        {
            _result = null;

            string fileName = Path.GetTempFileName();
            fileName = "D:\\test.html";

            string cookie = "ASP.NET_SessionId=maebhn55333a1unuwov03z45; CONTROLGROUPCONTACT_ContactInputView_dsadsadsada=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|BMV&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=dasdasd&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=dsada&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=7631296&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=abnc%40gmail.com; CONTROLGROUPCONTACT_ContactInputView_fdsfsdfdf=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|DLI&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=fsfdsf&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=34242&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=1761619&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=thienan289%40gmail.com; __utma=187758136.1446620650.1355320027.1356153307.1356158655.20; __utmb=187758136.1.10.1356158655; __utmc=187758136; __utmz=187758136.1356158655.20.18.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)";
            WebScraping webScraping = new AirMekongWebSraping();
            IWebScrapingDelegate webScrapingDelegate = webScraping.GetWebScrapingDelegate(param.BookingType);
            webScrapingDelegate.DownloadWebPage(param, fileName, cookie);

            GetPostData(fileName, param);

            string postData = string.Format(
                "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUBMGRk77h9CNekodLMZhdJu3riPx9ebN8%3D&pageToken=&AvailabilitySearchInputScheduleSelectView%24RadioButtonMarketStructure=RoundTrip&originStation1=HAN&AvailabilitySearchInputScheduleSelectView%24TextBoxMarketOrigin1=HAN&destinationStation1=SGN&AvailabilitySearchInputScheduleSelectView%24TextBoxMarketDestination1=SGN&AvailabilitySearchInputScheduleSelectView%24DropDownListMarketDay1=25&AvailabilitySearchInputScheduleSelectView%24DropDownListMarketMonth1=2012-12&AvailabilitySearchInputScheduleSelectView%24DropDownListMarketDateRange1=0%7C4&date_picker=2012-12-25&originStation2=SGN&AvailabilitySearchInputScheduleSelectView%24TextBoxMarketOrigin2=SGN&destinationStation2=HAN&AvailabilitySearchInputScheduleSelectView%24TextBoxMarketDestination2=HAN&AvailabilitySearchInputScheduleSelectView%24DropDownListMarketDay2=30&AvailabilitySearchInputScheduleSelectView%24DropDownListMarketMonth2=2012-12&AvailabilitySearchInputScheduleSelectView%24DropDownListMarketDateRange2=0%7C4&date_picker=2012-12-30&AvailabilitySearchInputScheduleSelectView%24DropDownListPassengerType_ADT=1&AvailabilitySearchInputScheduleSelectView%24DropDownListPassengerType_CHD=0&AvailabilitySearchInputScheduleSelectView%24DropDownListPassengerType_INFANT=0&AvailabilitySearchInputScheduleSelectView%24DropDownListSearchBy=columnView&ControlGroupScheduleSelectView%24AvailabilityInputScheduleSelectView%24HiddenFieldTabIndex1=3&ControlGroupScheduleSelectView%24AvailabilityInputScheduleSelectView%24market1={0}&ControlGroupScheduleSelectView%24AvailabilityInputScheduleSelectView%24HiddenFieldTabIndex2=3&ControlGroupScheduleSelectView%24AvailabilityInputScheduleSelectView%24market2={1}&ControlGroupScheduleSelectView%24AgreementInputScheduleSelectView%24CheckBoxAgreement=on&ControlGroupScheduleSelectView%24ButtonSubmit=Ti%E1%BA%BFp+t%E1%BB%A5c",
                _market1, _market2);

            WebClientEx webClient = WebClientEx.CreateMekongAirWebClient("https://booking.airmekong.com.vn/ScheduleSelect.aspx");
            webClient.Headers["Cookie"] =
                "ASP.NET_SessionId=maebhn55333a1unuwov03z45; CONTROLGROUPCONTACT_ContactInputView_dsadsadsada=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|BMV&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=dasdasd&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=dsada&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=7631296&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=abnc%40gmail.com; CONTROLGROUPCONTACT_ContactInputView_fdsfsdfdf=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|DLI&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=fsfdsf&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=34242&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=1761619&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=thienan289%40gmail.com; __utma=187758136.1446620650.1355320027.1356153307.1356158655.20; __utmb=187758136.1.10.1356158655; __utmc=187758136; __utmz=187758136.1356158655.20.18.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)";
            webClient.DownloadFileEx(postData, fileName);

            postData = string.Format("__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUBMGRk77h9CNekodLMZhdJu3riPx9ebN8%3D&pageToken=&AvailabilitySearchInputContactView%24RadioButtonMarketStructure=RoundTrip&originStation1=HAN&AvailabilitySearchInputContactView%24TextBoxMarketOrigin1=HAN&destinationStation1=SGN&AvailabilitySearchInputContactView%24TextBoxMarketDestination1=SGN&AvailabilitySearchInputContactView%24DropDownListMarketDay1=25&AvailabilitySearchInputContactView%24DropDownListMarketMonth1=2012-12&AvailabilitySearchInputContactView%24DropDownListMarketDateRange1=0%7C4&date_picker=2012-12-25&originStation2=SGN&AvailabilitySearchInputContactView%24TextBoxMarketOrigin2=SGN&destinationStation2=HAN&AvailabilitySearchInputContactView%24TextBoxMarketDestination2=HAN&AvailabilitySearchInputContactView%24DropDownListMarketDay2=30&AvailabilitySearchInputContactView%24DropDownListMarketMonth2=2012-12&AvailabilitySearchInputContactView%24DropDownListMarketDateRange2=0%7C4&date_picker=2012-12-30&AvailabilitySearchInputContactView%24DropDownListPassengerType_ADT=1&AvailabilitySearchInputContactView%24DropDownListPassengerType_CHD=0&AvailabilitySearchInputContactView%24DropDownListPassengerType_INFANT=0&AvailabilitySearchInputContactView%24DropDownListSearchBy=columnView&CONTROLGROUPCONTACT%24ContactInputView%24DropDownListTitle=MR&CONTROLGROUPCONTACT%24ContactInputView%24TextBoxLastName={1}&CONTROLGROUPCONTACT%24ContactInputView%24TextBoxFirstName={0}&CONTROLGROUPCONTACT%24ContactInputView%24TextBoxAddressLine1=ttt&CONTROLGROUPCONTACT%24ContactInputView%24DropDownListStateProvince=VN%7CSGN&CONTROLGROUPCONTACT%24ContactInputView%24DropDownListCountry=VN&CONTROLGROUPCONTACT%24ContactInputView%24TextBoxHomePhone={2}&CONTROLGROUPCONTACT%24ContactInputView%24TextBoxEmailAddress={3}&CONTROLGROUPCONTACT%24ContactInputView%24TextBoxFax=7528984&CONTROLGROUPCONTACT%24ItineraryDistributionInputView%24Distribution=0&CONTROLGROUPCONTACT%24ButtonSubmit=Ti%E1%BA%BFp+t%E1%BB%A5c", param.FirstName, param.LastName, param.Phone, param.Email);
            webClient = WebClientEx.CreateMekongAirWebClient("https://booking.airmekong.com.vn/Contact.aspx");
            webClient.Headers["Cookie"] =
                "ASP.NET_SessionId=maebhn55333a1unuwov03z45; CONTROLGROUPCONTACT_ContactInputView_dsadsadsada=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|BMV&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=dasdasd&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=dsada&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=7631296&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=abnc%40gmail.com; CONTROLGROUPCONTACT_ContactInputView_fdsfsdfdf=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|DLI&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=fsfdsf&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=34242&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=1761619&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=thienan289%40gmail.com; __utma=187758136.1446620650.1355320027.1356153307.1356158655.20; __utmb=187758136.1.10.1356158655; __utmc=187758136; __utmz=187758136.1356158655.20.18.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)";
            webClient.DownloadFileEx(postData, fileName);

            postData = string.Format("__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUBMGRk77h9CNekodLMZhdJu3riPx9ebN8%3D&pageToken=&AvailabilitySearchInputPassengerView%24RadioButtonMarketStructure=RoundTrip&originStation1=HAN&AvailabilitySearchInputPassengerView%24TextBoxMarketOrigin1=HAN&destinationStation1=SGN&AvailabilitySearchInputPassengerView%24TextBoxMarketDestination1=SGN&AvailabilitySearchInputPassengerView%24DropDownListMarketDay1=25&AvailabilitySearchInputPassengerView%24DropDownListMarketMonth1=2012-12&AvailabilitySearchInputPassengerView%24DropDownListMarketDateRange1=0%7C4&date_picker=2012-12-25&originStation2=SGN&AvailabilitySearchInputPassengerView%24TextBoxMarketOrigin2=SGN&destinationStation2=HAN&AvailabilitySearchInputPassengerView%24TextBoxMarketDestination2=HAN&AvailabilitySearchInputPassengerView%24DropDownListMarketDay2=30&AvailabilitySearchInputPassengerView%24DropDownListMarketMonth2=2012-12&AvailabilitySearchInputPassengerView%24DropDownListMarketDateRange2=0%7C4&date_picker=2012-12-30&AvailabilitySearchInputPassengerView%24DropDownListPassengerType_ADT=1&AvailabilitySearchInputPassengerView%24DropDownListPassengerType_CHD=0&AvailabilitySearchInputPassengerView%24DropDownListPassengerType_INFANT=0&AvailabilitySearchInputPassengerView%24DropDownListSearchBy=columnView&CONTROLGROUPPASSENGER%24PassengerInputViewPassengerView%24DropDownListTitle_0=MR&CONTROLGROUPPASSENGER%24PassengerInputViewPassengerView%24TextBoxLastName_0=Nguyen&CONTROLGROUPPASSENGER%24PassengerInputViewPassengerView%24TextBoxFirstName_0=Ngoc&CONTROLGROUPPASSENGER%24PassengerInputViewPassengerView%24TextBoxProgramNumber_0=&CONTROLGROUPPASSENGER%24PassengerInputViewPassengerView%24DropDownListProgram_0=UAT&CONTROLGROUPPASSENGER%24ButtonSubmit=Ti%E1%BA%BFp+t%E1%BB%A5c");
            webClient = WebClientEx.CreateMekongAirWebClient("https://booking.airmekong.com.vn/Passenger.aspx");
            webClient.Headers["Cookie"] =
                "ASP.NET_SessionId=maebhn55333a1unuwov03z45; CONTROLGROUPCONTACT_ContactInputView_dsadsadsada=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|BMV&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=dasdasd&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=dsada&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=7631296&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=abnc%40gmail.com; CONTROLGROUPCONTACT_ContactInputView_fdsfsdfdf=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|DLI&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=fsfdsf&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=34242&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=1761619&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=thienan289%40gmail.com; __utma=187758136.1446620650.1355320027.1356153307.1356158655.20; __utmb=187758136.1.10.1356158655; __utmc=187758136; __utmz=187758136.1356158655.20.18.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)";
            webClient.DownloadFileEx(postData, fileName);

            postData = string.Format(
                "__EVENTTARGET=CONTROLGROUPPAYMENTBOTTOM%24PaymentInputViewPaymentView&__EVENTARGUMENT=HOLD&__VIEWSTATE=%2FwEPDwUBMGRk77h9CNekodLMZhdJu3riPx9ebN8%3D&pageToken=&AvailabilitySearchInputPaymentView%24RadioButtonMarketStructure=RoundTrip&originStation1=HAN&AvailabilitySearchInputPaymentView%24TextBoxMarketOrigin1=HAN&destinationStation1=SGN&AvailabilitySearchInputPaymentView%24TextBoxMarketDestination1=SGN&AvailabilitySearchInputPaymentView%24DropDownListMarketDay1=25&AvailabilitySearchInputPaymentView%24DropDownListMarketMonth1=2012-12&AvailabilitySearchInputPaymentView%24DropDownListMarketDateRange1=0%7C4&date_picker=2012-12-25&originStation2=SGN&AvailabilitySearchInputPaymentView%24TextBoxMarketOrigin2=SGN&destinationStation2=HAN&AvailabilitySearchInputPaymentView%24TextBoxMarketDestination2=HAN&AvailabilitySearchInputPaymentView%24DropDownListMarketDay2=30&AvailabilitySearchInputPaymentView%24DropDownListMarketMonth2=2012-12&AvailabilitySearchInputPaymentView%24DropDownListMarketDateRange2=0%7C4&date_picker=2012-12-30&AvailabilitySearchInputPaymentView%24DropDownListPassengerType_ADT=1&AvailabilitySearchInputPaymentView%24DropDownListPassengerType_CHD=0&AvailabilitySearchInputPaymentView%24DropDownListPassengerType_INFANT=0&AvailabilitySearchInputPaymentView%24DropDownListSearchBy=columnView&CONTROLGROUPPAYMENTBOTTOM%24PaymentInputViewPaymentView%24DropDownListPaymentMethodCode=ExternalAccount%3AAX&CONTROLGROUPPAYMENTBOTTOM%24PaymentInputViewPaymentView%24TextBoxAMT=4.308.000&CONTROLGROUPPAYMENTBOTTOM%24PaymentInputViewPaymentView%24TextBoxACCTNO=&CONTROLGROUPPAYMENTBOTTOM%24PaymentInputViewPaymentView%24DropDownListEXPDAT_Month=12&CONTROLGROUPPAYMENTBOTTOM%24PaymentInputViewPaymentView%24DropDownListEXPDAT_Year=2012&CONTROLGROUPPAYMENTBOTTOM%24PaymentInputViewPaymentView%24TextBoxCC__AccountHolderName=&CONTROLGROUPPAYMENTBOTTOM%24PaymentInputViewPaymentView%24TextBoxCC__VerificationCode=");
            webClient = WebClientEx.CreateMekongAirWebClient("https://booking.airmekong.com.vn/Payment.aspx");
            webClient.Headers["Cookie"] =
                "ASP.NET_SessionId=maebhn55333a1unuwov03z45; CONTROLGROUPCONTACT_ContactInputView_dsadsadsada=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|BMV&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=dasdasd&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=dsada&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=7631296&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=abnc%40gmail.com; CONTROLGROUPCONTACT_ContactInputView_fdsfsdfdf=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|DLI&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=fsfdsf&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=34242&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=1761619&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=thienan289%40gmail.com; __utma=187758136.1446620650.1355320027.1356153307.1356158655.20; __utmb=187758136.1.10.1356158655; __utmc=187758136; __utmz=187758136.1356158655.20.18.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)";
            webClient.DownloadFileEx(postData, fileName);

            postData = string.Format(
                "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUBMGRk77h9CNekodLMZhdJu3riPx9ebN8%3D&pageToken=&AvailabilitySearchInputPaymentView%24RadioButtonMarketStructure=RoundTrip&originStation1=HAN&AvailabilitySearchInputPaymentView%24TextBoxMarketOrigin1=HAN&destinationStation1=SGN&AvailabilitySearchInputPaymentView%24TextBoxMarketDestination1=SGN&AvailabilitySearchInputPaymentView%24DropDownListMarketDay1=25&AvailabilitySearchInputPaymentView%24DropDownListMarketMonth1=2012-12&AvailabilitySearchInputPaymentView%24DropDownListMarketDateRange1=0%7C4&date_picker=2012-12-25&originStation2=SGN&AvailabilitySearchInputPaymentView%24TextBoxMarketOrigin2=SGN&destinationStation2=HAN&AvailabilitySearchInputPaymentView%24TextBoxMarketDestination2=HAN&AvailabilitySearchInputPaymentView%24DropDownListMarketDay2=30&AvailabilitySearchInputPaymentView%24DropDownListMarketMonth2=2012-12&AvailabilitySearchInputPaymentView%24DropDownListMarketDateRange2=0%7C4&date_picker=2012-12-30&AvailabilitySearchInputPaymentView%24DropDownListPassengerType_ADT=1&AvailabilitySearchInputPaymentView%24DropDownListPassengerType_CHD=0&AvailabilitySearchInputPaymentView%24DropDownListPassengerType_INFANT=0&AvailabilitySearchInputPaymentView%24DropDownListSearchBy=columnView&DropdowDS=ABO&CONTROLGROUPPAYMENTBOTTOM%24ButtonSubmit=Thanh+to%C3%A1n");
            webClient = WebClientEx.CreateMekongAirWebClient("https://booking.airmekong.com.vn/Payment.aspx");
            webClient.Headers["Cookie"] =
                "ASP.NET_SessionId=maebhn55333a1unuwov03z45; CONTROLGROUPCONTACT_ContactInputView_dsadsadsada=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|BMV&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=dasdasd&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=dsada&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=7631296&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=abnc%40gmail.com; CONTROLGROUPCONTACT_ContactInputView_fdsfsdfdf=CONTROLGROUPCONTACT_ContactInputView_DropDownListTitle=MR&CONTROLGROUPCONTACT_ContactInputView_DropDownListSuffix=&CONTROLGROUPCONTACT_ContactInputView_DropDownListStateProvince=VN|DLI&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine1=fsfdsf&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine2=&CONTROLGROUPCONTACT_ContactInputView_TextBoxAddressLine3=&CONTROLGROUPCONTACT_ContactInputView_TextBoxCity=&CONTROLGROUPCONTACT_ContactInputView_TextBoxPostalCode=&CONTROLGROUPCONTACT_ContactInputView_DropDownListCountry=VN&CONTROLGROUPCONTACT_ContactInputView_TextBoxHomePhone=34242&CONTROLGROUPCONTACT_ContactInputView_TextBoxWorkPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxOtherPhone=&CONTROLGROUPCONTACT_ContactInputView_TextBoxFax=1761619&CONTROLGROUPCONTACT_ContactInputView_TextBoxEmailAddress=thienan289%40gmail.com; __utma=187758136.1446620650.1355320027.1356153307.1356158655.20; __utmb=187758136.1.10.1356158655; __utmc=187758136; __utmz=187758136.1356158655.20.18.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)";
            webClient.DownloadFileEx(postData, fileName);

            ParseResult(fileName);
            File.Delete(fileName);
        }

        private void GetPostData(string fileName, FlightRegisterParameters param)
        {
            HtmlDocument document = new HtmlDocument();
            document.Load(fileName);

            _market1 = GetComboboxValue(document, param.DepartFlightNo, "availabilityTable0");
            _market2 = "";

            if (param.BookingType == "roundtrip")
            {
                _market2 = GetComboboxValue(document, param.ReturnFlightNo, "availabilityTable1");
            }
        }

        private string GetComboboxValue( HtmlDocument document, string flightNo, string tableId)
        {
            string xpath = String.Format("//table[@id='{0}']//tr", tableId);
            HtmlNodeCollection rows = document.DocumentNode.SelectNodes(xpath);
            if (null == rows)
            {
                return "";
            }

            foreach (HtmlNode row in rows)
            {
                HtmlNodeCollection columns = row.SelectNodes("./td");
                if (columns != null && 8 == columns.Count)
                {
                    HtmlNode flight = columns.ElementAt(0);

                    string tempFlightNo = Utilities.ExtractNumberAndCharacter(flight.InnerText);
                    string inputFlightNo = Utilities.ExtractNumberAndCharacter(flightNo);

                    if (tempFlightNo == inputFlightNo)
                    {
                        HtmlNodeCollection pricesNode = row.SelectNodes("./td/p");
                        if (null != pricesNode && pricesNode.Count > 0)
                        {
                            HtmlNode combobox = pricesNode.Last().SelectSingleNode("./input");
                            if (combobox != null)
                            {
                                return combobox.GetAttributeValue("value", "");
                            }
                        }
                    }
                    
                }
            }
            return "";
        }

        
    }
}
